package com.itheima.mapper;

import com.itheima.pojo.CheckGroup;
import com.itheima.pojo.CheckItem;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface CheckGroupMapper {

    //新增检查项
    void addGroup(CheckGroup checkGroup);

    //向检查项和检查组的中间表添加各自的id
    void addGroupAndCheckItem(@Param("checkgruopId") Integer checkgruopId,@Param("checkitemId") Integer checkitemId);

    //检查组分页查询
    List<CheckGroup> findPage(@Param("queryString") String queryString);

    //根据检查组id获取对应的检查项id
    Integer[] findCheckItemIdsByCheckGroupId(Integer id);

    //根据检查组id删除对应t_checkgroup_checkitem表数据
    @Delete("delete from t_checkgroup_checkitem where checkgroup_id=#{id}")
    void deleteAssociation(@Param("id") Integer id);

    //修改检查组
    void editGroup(CheckGroup checkGroup);

    //判断该检查组是否存在套餐中
    @Select("select count(*) from t_setmeal_checkgroup where CHECKGROUP_ID=#{id}")
    int findSetmealCheckgroup(@Param("id") Integer id);

    //删除检查组
    @Update("UPDATE t_checkgroup set IS_DELETE=1 where id=#{id}")
    void deleteCheckGroupById(@Param("id") Integer id);

    //在套餐中查询所有检查组
    @Select("select * from t_checkgroup")
    List<CheckGroup> findAll();

    //根据套餐id查询对应检查组的数据
    @Select("select * from t_checkgroup where id in(select checkgroup_id from t_setmeal_checkgroup where setmeal_id=#{id}) and IS_DELETE=0")
    List<CheckGroup> findCheckGroupBySetMealId(Integer id);
}
